<?php
/**
 * Created by PhpStorm.
 * User: wzy12
 * Date: 2018/11/8
 * Time: 16:45
 */

namespace app\admin\controller;


class Finance extends Base
{
    /**
     * 资金统计
     */
    public function statistics(){
        $search_key = input();
        unset($search_key['/admin/finance/statistics_html']);

        $list = model('Order') -> order_complete($search_key);
        unset($search_key['page']);
        if(!$search_key){
            $search_key = null;
        }

        $this -> assign('search_key', $search_key);
        $this -> assign('list', $list);

        return $this -> fetch();
    }

    /**
     * 发票列表
     */
    public function invoice(){
        $search_key = input();
        unset($search_key['/admin/finance/invoice_html']);

        $list = model('Invoice') -> resList($search_key);
        unset($search_key['page']);
        if(!$search_key){
            $search_key = null;
        }

        $this -> assign('search_key', $search_key);
        $this -> assign('list', $list);

        return $this -> fetch();
    }

    public function invoice_cat(){
        if($this -> request -> isAjax()){
            $data = input('post.');
            $result = model('OrderAction') -> operation($data);
            if(!$result['code']){
                return $this -> error($result['msg'], '', ['token' => $this -> request -> token()]);
            }else{
                return $this -> success($result['msg'], url('finance/invoice_cat',['id' => $data['order_id']]), ['token' => $this -> request -> token()]);
            }
        }else{
            $id = input('id', 0);
            if($id){
                $order = model('Order') -> Cat($id);

                $this -> assign('order', $order);
                return $this -> fetch();
            }else{
                return $this -> error('非法请求', url('index/index'));
            }
        }
    }
}